//
//  ZFBusinessTypeCell.m
//  04-商家分类
//
//  Created by heima on 16/6/25.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "Masonry.h"
#import "ZFBusinessTypeCell.h"
#import "UIImageView+WebCache.h"

@interface ZFBusinessTypeCell ()

@property (nonatomic, weak) UIImageView* iconView;
@property (nonatomic, weak) UILabel* nameLabel;

@end

@implementation ZFBusinessTypeCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

// 会调用两次.告诉系统是否是高亮状态
// 当手指按下的时候调用一次 参数为yes 表示系统为高亮(赶紧换高亮的状态的图片)
// 当手指抬起的时候调用一次 参数为no 表示系统为不高亮(赶紧换普通的状态的图片)
- (void)setHighlighted:(BOOL)highlighted
{
    self.backgroundColor = highlighted ? [UIColor colorWithWhite:0.8 alpha:1] : [UIColor whiteColor];
}

- (void)setBusinessType:(DMFunctionModel*)businessType
{
    _businessType = businessType;

    // 把数据放在控件上
    [self.iconView sd_setImageWithURL:[NSURL URLWithString: businessType.img]placeholderImage:[UIImage imageNamed:@"icon_holder_57x57"]];
//    self.iconView.image = [UIImage imageNamed:businessType.icon];
    self.nameLabel.text = businessType.name;
}

// 初始化控件
- (void)setupUI
{

    // icon
    UIImageView* iconView = [[UIImageView alloc] init];
//    iconView.image = [UIImage imageNamed:@"bus"];
    [self.contentView addSubview:iconView];

    // name
    UILabel* nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = [UIColor darkGrayColor];
    nameLabel.font = [UIFont systemFontOfSize:14];

    [self.contentView addSubview:nameLabel];

    // 自动布局
    [iconView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.top.offset(20);
        make.centerX.equalTo(self.contentView);
        make.width.height.offset(35);
    }];

    [nameLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.top.equalTo(iconView.mas_bottom).offset(8);
        make.centerX.equalTo(iconView);
    }];

    self.iconView = iconView;
    self.nameLabel = nameLabel;
}

@end
